package com.oneraku.service.config;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * @Author: hui.ren@huberbuy.com
 * @Date: 2020/3/10 15:23
 */
@Component
public class ApplicationContextProvider implements ApplicationContextAware {
    private static ApplicationContext context;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
            context = applicationContext;
    }

    public static <T> T getBean(Class<T> tClass){
        return context.getBean(tClass);
    }
    public static <T> T getBean(String name, Class<T> tClass) {
        return context.getBean(name, tClass);
    }
}
